package com.lz.sports.bean

import android.os.Parcel
import android.os.Parcelable
import com.lz.library.proguard.IProguardField
import com.google.gson.annotations.Expose
import com.google.gson.annotations.SerializedName

//项目配置, 评分规则
class ProjectConfig() : Parcelable, IProguardField {

    companion object {

        //规则适用男性
        const val MALE = 1

        //规则适用女性
        const val FEMALE = 2

        @JvmField
        val CREATOR = object : Parcelable.Creator<ProjectConfig> {
            override fun createFromParcel(parcel: Parcel): ProjectConfig {
                return ProjectConfig(parcel)
            }

            override fun newArray(size: Int): Array<ProjectConfig?> {
                return arrayOfNulls(size)
            }
        }
    }

    @Expose
    var id: Int = 0

    //适用年级
    @Expose
    var applicableGrade: String = ""

    //适用性别 1男2女
    @Expose
    var applicableSex: Int = MALE

    //区域ID
    @Expose
    var areaId: Int = 0

    //计算方式  1 计时, 2计数, 3 限时计数
    @Expose
    var calculationMethod: Int = 0

    //适用项目代码
    @Expose
    var projectCode: String = ""

    //适用项目名称
    @Expose
    var projectName: String = ""

    //1体测 2体考
    @Expose
    var examType: Int = 0

    //项目类别 1 耐力类, 2素质类, 3技能类
    @Expose
    var projectType: Int = 0

    //状态 1启用 0暂停
    @Expose
    var status: Int = 0

    //规则详情列表
    @Expose
    @SerializedName("busProjectConfigDetailList")
    var detailList: List<ConfigDetail>? = null

    constructor(parcel: Parcel) : this() {
        id = parcel.readInt()
        applicableGrade = parcel.readString()!!
        applicableSex = parcel.readInt()
        areaId = parcel.readInt()
        calculationMethod = parcel.readInt()
        projectCode = parcel.readString()!!
        projectName = parcel.readString()!!
        examType = parcel.readInt()
        projectType = parcel.readInt()
        status = parcel.readInt()
        detailList = parcel.createTypedArrayList(ConfigDetail)
    }

    override fun writeToParcel(parcel: Parcel, flags: Int) {
        parcel.writeInt(id)
        parcel.writeString(applicableGrade)
        parcel.writeInt(applicableSex)
        parcel.writeInt(areaId)
        parcel.writeInt(calculationMethod)
        parcel.writeString(projectCode)
        parcel.writeString(projectName)
        parcel.writeInt(examType)
        parcel.writeInt(projectType)
        parcel.writeInt(status)
        parcel.writeTypedList(detailList)
    }

    override fun describeContents(): Int {
        return 0
    }

    //评分规则祥情
    class ConfigDetail() : Parcelable, IProguardField {

        //适用性别 1男2女
        @Expose
        var applicableSex: Int = MALE

        @Expose
        var id: Int = 0

        //超始值
        @Expose
        var startValue: Float = 0f

        //结束值
        @Expose
        var endValue: Float = 0f

        //得分
        @Expose
        var score: Float = 0f

        //评分优秀, 差..
        @Expose
        var evaluate: String = ""

        fun isMale(): Boolean = applicableSex == MALE

        constructor(parcel: Parcel) : this() {
            id = parcel.readInt()
            startValue = parcel.readFloat()
            endValue = parcel.readFloat()
            score = parcel.readFloat()
            evaluate = parcel.readString()!!
        }

        override fun writeToParcel(parcel: Parcel, flags: Int) {
            parcel.writeInt(id)
            parcel.writeFloat(startValue)
            parcel.writeFloat(endValue)
            parcel.writeFloat(score)
            parcel.writeString(evaluate)
        }

        override fun describeContents(): Int {
            return 0
        }

        companion object CREATOR : Parcelable.Creator<ConfigDetail> {
            override fun createFromParcel(parcel: Parcel): ConfigDetail {
                return ConfigDetail(parcel)
            }

            override fun newArray(size: Int): Array<ConfigDetail?> {
                return arrayOfNulls(size)
            }
        }
    }

}